package com.jtjrenren.android.taxi.passenger.core.wallect.jindou;

import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.jtjrenren.android.taxi.passenger.base.BaseActivity;
import com.jtjrenren.android.taxi.passenger.core.adapter.JindouHistoryAdapter;
import com.jtjrenren.android.taxi.passenger.R;
import com.jtjrenren.android.taxi.passenger.bean.api.ApiJdList;
import com.jtjrenren.android.taxi.passenger.manger.AppManger;
import com.jtjrenren.android.taxi.passenger.manger.api.ApiWorks;
import com.jtjrenren.android.taxi.passenger.utils.DividerItemDecoration;
import com.jtjrenren.android.taxi.passenger.utils.InitView;
import com.library.weidget.AutoLoadRecyclerView;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/1/29.
 */
public class JinDouHistoryActivity extends BaseActivity {
    @BindView(R.id.wallect_jindou_history_list)
     AutoLoadRecyclerView rcy_list;
    @BindView(R.id.nocontent)
     LinearLayout ll_nocontent;
    @BindView(R.id.title)
    TextView tv_title;

    private JindouHistoryAdapter jindouHistoryAdapter;

    @Override
    public int getLayoutId() {
        return R.layout.aty_wallect_jindouhistory;
    }

    @Override
    public void init() {
        tv_title.setText("金豆明细");

        InitView.initVritalReclyView(this, rcy_list);
        rcy_list.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));

        jindouHistoryAdapter = new JindouHistoryAdapter(this);
        rcy_list.setAdapter(jindouHistoryAdapter);

        getJindouHistory();
    }

    @OnClick(R.id.title_left)
    public void clickBack(){
        finish();
    }

    private void getJindouHistory() {
        showWaittingDialog(null,false);
        ApiWorks.getJinDouHistory(AppManger.getInstance().user.getWorkNo(),
                new ApiWorks.ResponseListener<ApiJdList>() {
                    @Override
                    public void onResponse(ApiJdList apiJdList) {
                        dismissWaittingDialog();
                        if (apiJdList!=null&&apiJdList.getRecordList()!=null&&apiJdList.getRecordList().size()>0){
                            showNoDataView(false);
                            jindouHistoryAdapter.replace(apiJdList.getRecordList());
                        }else {
                            showNoDataView(true);
                        }
                    }
                });

    }

    private void showNoDataView(boolean isNodata) {
        if (isNodata) {
            ll_nocontent.setVisibility(View.VISIBLE);
            rcy_list.setVisibility(View.GONE);
        } else {
            ll_nocontent.setVisibility(View.GONE);
            rcy_list.setVisibility(View.VISIBLE);
        }
    }
}
